package com.yc.snack.dao.impl;

import com.yc.snack.dao.IProductInfoDao;
import com.yc.snack.dao.util.DBUtil;
import com.yc.snack.entity.ProductInfo;

import java.util.List;

/**
 * @Auther: HuYang
 * @Date: 2022/11/18 - 11 - 18 - 21:00
 * @Description: com.yc.snack.dao.impl
 * @version: 1.0
 */
public class ProductInfoDaoImpl implements IProductInfoDao {

    @Override
    public int add(ProductInfo productInfo) {
        DBUtil dbUtil = new DBUtil();
        String sql = "insert into goodsinfo values(0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)";
        return dbUtil.update(sql, productInfo.getGname(), productInfo.getTno(), productInfo.getPrice(),
                productInfo.getIntro(), productInfo.getBalance(), productInfo.getPics(), productInfo.getUnit(),
                productInfo.getQperied(), productInfo.getWeight(), productInfo.getDescr());
    }

    @Override
    public List<ProductInfo> finds(int page, int rows) {
        DBUtil dbUtil = new DBUtil();
        String sql = "select gno, gname, price, weight, pics from goodsinfo order by gno desc limit ?, ?";
        return dbUtil.finds(ProductInfo.class, sql, (page - 1) * rows, rows);
    }

    @Override
    public int total() {
        DBUtil dbUtil = new DBUtil();
        String sql = "select count(gno) from goodsinfo";
        return Integer.parseInt(dbUtil.findStr(sql));
    }
}
